package com.itheima.spring.bestpractive.controller.home;

import com.itheima.spring.bestpractive.common.myResult.R;
import com.itheima.spring.bestpractive.pojo.AssessmentIndicator;
import com.itheima.spring.bestpractive.pojo.AssessmentPlan;
import com.itheima.spring.bestpractive.service.AssessmentService;
import com.itheima.spring.bestpractive.service.EmpService;
import com.itheima.spring.bestpractive.vo.resp.assessment.AssessmentIndicatorRespVo;
import com.itheima.spring.bestpractive.vo.resp.assessment.AssessmentPlanRespVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0
 * @author: HZY
 * @date: 2025/6/29 15:37
 * @Content:
 */
@RestController
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private AssessmentService assessmentService;


    @Autowired
    private EmpService empService;

    @GetMapping("/search")
    @Operation(description = "根据名称查询计划")
    public R searchPlan(String planName) {
        List<AssessmentPlan> planByName = assessmentService.getPlanByName(planName);
        List<AssessmentPlanRespVo> planRespVos = planByName.stream().map(plans -> {
            AssessmentPlanRespVo planRespVo = new AssessmentPlanRespVo();
            BeanUtils.copyProperties(plans, planRespVo);
            return planRespVo;
        }).toList();
        return R.success(planRespVos);
    }

    @GetMapping("/searchPlan/indicators")
    @Operation(description = "根据计划id查询指标")
    public R searchIndicators(long planId) {
        AssessmentPlan plan = new AssessmentPlan();
        plan.setPlanId(planId);
        List<AssessmentIndicator> assessmentIndicatorList = assessmentService.getAssessmentIndicatorList(plan);
        return R.success(assessmentIndicatorList);
    }

    @GetMapping("/plan")
    @Operation(description = "获取部门计划")
    public R getPlan() {
        List<AssessmentPlan> allPlan = assessmentService.getAllPlan();
        List<AssessmentPlanRespVo> assessmentPlanRespVoList = allPlan.stream().map(plan -> {
            AssessmentPlanRespVo planRespVo = new AssessmentPlanRespVo();
            BeanUtils.copyProperties(plan, planRespVo);
            return planRespVo;
        }).toList();
        return R.success(assessmentPlanRespVoList);
    }

    @GetMapping("/getAllEvaluator")
    @Operation(description = "获取所有部门的考核人员")
    public R getAllEvaluator() {
        return R.success(empService.getAllEvaluator());
    }
}
